package com.copa.l1807;

import java.util.*;

/**
 * @author copa
 * @createDate 2023-01-12 16:43
 * @function 哈希表+模拟
 */
public class Test2 {

    public String evaluate(String s, List<List<String>> knowledge) {
        Map<String, String> keyContentMap = new HashMap<>();
        for (List<String> keyContent : knowledge) {
            keyContentMap.put(keyContent.get(0), keyContent.get(1));
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '(') {
                StringBuilder sbTemp = new StringBuilder();
                while (s.charAt(++i) != ')') {
                    sbTemp.append(s.charAt(i));
                }
                sb.append(keyContentMap.getOrDefault(sbTemp.toString(), "?"));
                continue;
            }
            sb.append(c);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String s = "(name)is(age)yearsold";
        List<List<String>> knowledge = new ArrayList<>();
        List<String> keyContent = new ArrayList<>();
        keyContent.add("name");
        keyContent.add("bob");
        knowledge.add(keyContent);
        keyContent = new ArrayList<>();
        keyContent.add("age");
        keyContent.add("two");
        knowledge.add(keyContent);
        System.out.println(new Test2().evaluate(s, knowledge));
    }
}
